package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Set;

/**
 * @author wangxin
 * @version 1.0
 */
public interface PermissionDao {

    Set<Permission> findPermissionsByRoleId(Integer roleId);

    /**
     * 分页查询
     * @return
     */
    Page<Permission> findPage(String queryString);

    /**
     * 新增权限
     * @param permission
     * @return  返回sql执行之后影响的记录数
     */
    @Insert("INSERT into t_permission(name, keyword, description) " +
            "VALUES(#{name}, #{keyword}, #{description})")
    int add(Permission permission);

    /**
     * find permission by id
     * @param id
     * @return
     */
    @Select("select * from t_permission where id = #{id}")
    Permission findById(Integer id);

    /**
     * 编辑权限
     * @param permission
     * @return  返回sql执行之后影响的记录数
     */
    @Update("UPDATE t_permission set name = #{name}, keyword = #{keyword}, " +
            "description = #{description} where id = #{id}")
    int edit(Permission permission);

    /**
     * 根据权限id 在权限表中删除权限
     * @param id
     * @return
     */
    @Delete("DELETE FROM t_permission where id = #{id}")
    int deleteById(Integer id);
}
